#{extends 'Admin_main.html' /}
<div class="block span10" style="margin-left: 20px;">
    <a href="#tablewidget" class="block-heading" data-toggle="collapse">菜单管理</a>
    <div class="btn-toolbar" style="margin-left: 20px;">

        <a href="" class="btn btn-primary">导入</a>
        <a href="" class="btn btn-primary">导出</a>

        <a href="#myModal" data-toggle="modal" onclick="Payments()" class="btn btn-primary">转赠金额</a>
        <a href="#myModal" data-toggle="modal" onclick="reduce()" class="btn btn-primary">手动扣除</a>
        <a href="/ShopRecharge/index.html" class="btn btn-primary">消费记录查看</a>
    </div>
    <div id="tablewidget" class="block-body collapse in">
        <table class="table table-bordered table-striped">
            <tr>
                <th>编号</th>
                <th>用户名</th>
                <th>身份证信息</th>
                <th>邮件信息</th>
                <th>电话</th>
                <th>浏览数</th>
                <th>模板数</th>
                <th>余额</th>
                <th>签到天数</th>
            </tr>
        #{list list,as:'list'}
            <tr>

                <td>
                    #{if list.Id == null}
                        暂无数据
                    #{/if}
                    #{else }
                    ${list.Id}
                    #{/else}
                </td>
                <td>
                    #{if list.Name == null}
                        暂无数据
                    #{/if}
                    #{else }
                    ${list.Name}
                    #{/else}
                </td>
                <td>
                    #{if list.IDS == null}
                        暂无数据
                    #{/if}
                    #{else }
                    ${list.IDS}
                    #{/else}
                </td>
                <td>
                    #{if list.Email == null}
                        暂无数据
                    #{/if}
                    #{else }
                    ${list.Email}
                    #{/else}
                </td>
                <td>
                    #{if list.IPone == null}
                        暂无数据
                    #{/if}
                    #{else }
                    ${list.IPone}
                    #{/else}
                </td>
                <td>
                    #{if list.Balance == null}
                        暂无数据
                    #{/if}
                    #{else }
                    ${list.Balance}
                    #{/else}
                </td>
                <td>
                    #{if list.Header == null}
                        暂无数据
                    #{/if}
                    #{else }
                    ${list.Header}
                    #{/else}
                </td>
                <td>
                    #{if list.money == null}
                        暂无数据
                    #{/if}
                    #{else }
                    ${list.money}
                    #{/else}
                </td>
                <td>
                    #{if list.Day == null}
                        暂无数据
                    #{/if}
                    #{else }
                    ${list.Day}
                    #{/else}
                </td>
            </tr>
        #{/list}
        </table>
    </div>
</div>
<input type="hidden" id="ids">
<div class="modal small hide fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="
display: none;">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 id="myModalLabel">在线赠送</h3>
    </div>
    <div class="modal-body">
        <label>图币赠送信息</label>
        <select name="Payment" id="Payment" class="Payment1">
            #{list payments,as:'payments'}
                <option value="${payments.Id}">${payments.title}</option>
            #{/list}
        </select>
        <select name="Payment" id="Payment" class="Payments">
            #{list paymentList,as:'paymentList'}
                <option value="${paymentList.Id}">${paymentList.title}</option>
            #{/list}
        </select>
        <label for="">账户</label>
        <select name="systemUsersList" id="systemUsersList">
            #{list systemUsersList,as:'systemUsersList'}
                <option value="${systemUsersList.Id}">${systemUsersList.UserName}</option>
            #{/list}
        </select>


        <label for="">金额</label>
        <select name="moneys" id="moneys">
            <option value="10">10</option>
            <option value="20">20</option>
            <option value="30">30</option>
            <option value="40">40</option>
            <option value="50">50</option>
            <option value="60">60</option>
            <option value="70">70</option>
            <option value="80">80</option>
            <option value="90">90</option>
            <option value="100">100</option>
        </select>
        <label for="">是否发送邮件</label>
        <input type="checkbox"id="type">
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
        <a href="#myModal1" class="btn btn-primary" data-toggle="modal" onclick="Payment()">赠送</a>
    </div>
</div>
<div class="modal small hide fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 id="myModalLabels">删除数据</h3>
    </div>
    <div class="modal-body" id="bodys">
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
        <button class="btn btn-primary" data-dismiss="modal" >删除</button>
    </div>
</div>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script>
    function Payment(){
       var Payment=document.getElementById("Payment").value;
       var systemUsersList=document.getElementById("systemUsersList").value;
       var moneys=document.getElementById("moneys").value;
       var type=0;
       if($("#type")[0].checked) {
           type=1
       }
       if($.isEmptyObject(Payment)||$.isEmptyObject(systemUsersList)||$.isEmptyObject(systemUsersList)){
           document.getElementById("myModalLabel").innerHTML="发送失败";
           document.getElementById("myModalLabel").innerHTML="请检查填写数据，数据不得为空！";
       }else {
            var ids = document.getElementById("ids").value;
            if(ids>0){
                $.ajax({
                    type: "POST",
                    url: "/Payment/Paymsg.html",
                    data:{Payment:Payment,systemUsersList:systemUsersList,moneys:moneys,type:type},
                    dataType: "json",
                    success: function(data){
                        if(data.code == -1){
                            document.getElementById("myModalLabels").innerHTML = "扣除失败";
                            var content = " <p>扣除失败，保存消费信息失败</p>";
                            document.getElementById("bodys").innerHTML = content;
                        }else if(data.code == -2){
                            document.getElementById("myModalLabels").innerHTML = "扣除失败";
                            var content = " <p>扣除失败，更新用户信息失败</p>";
                            document.getElementById("bodys").innerHTML = content;
                        }else if(data.code == -3){
                            document.getElementById("myModalLabels").innerHTML = "扣除失败";
                            var content = " <p>扣除失败，更新用户消息记录失败</p>";
                            document.getElementById("bodys").innerHTML = content;
                        }else if(data.code == -4){
                            document.getElementById("myModalLabels").innerHTML = "扣除失败";
                            var content = " <p>扣除失败，发送邮件失败</p>";
                            document.getElementById("bodys").innerHTML = content;
                        }else if(data.code == 1){
                            document.getElementById("myModalLabels").innerHTML = "扣除成功";
                            var content = " <p>扣除成功，请检查用户余额</p>";
                            document.getElementById("bodys").innerHTML = content;
                        }else if(data.code==0){
                            document.getElementById("myModalLabels").innerHTML = "扣除失败";
                            var content = " <p>扣除失败，余额资金不足</p>";
                            document.getElementById("bodys").innerHTML = content;
                        }
                    }
                });
            }else{
                $.ajax({
                    type: "POST",
                    url: "/Payment/Paymsg.html",
                    data:{Payment:Payment,systemUsersList:systemUsersList,moneys:moneys,type:type},
                    dataType: "json",
                    success: function(data){
                        if(data.code == -1){
                            document.getElementById("myModalLabels").innerHTML = "充值失败";
                            var content = " <p>充值失败，保存消费信息失败</p>";
                            document.getElementById("bodys").innerHTML = content;
                        }else if(data.code == -2){
                            document.getElementById("myModalLabels").innerHTML = "充值失败";
                            var content = " <p>充值失败，更新用户信息失败</p>";
                            document.getElementById("bodys").innerHTML = content;
                        }else if(data.code == -3){
                            document.getElementById("myModalLabels").innerHTML = "充值失败";
                            var content = " <p>充值失败，更新用户消息记录失败</p>";
                            document.getElementById("bodys").innerHTML = content;
                        }else if(data.code == -4){
                            document.getElementById("myModalLabels").innerHTML = "充值失败";
                            var content = " <p>充值失败，发送邮件失败</p>";
                            document.getElementById("bodys").innerHTML = content;
                        }else if(data.code == 1){
                            document.getElementById("myModalLabels").innerHTML = "发送成功";
                            var content = " <p>充值成功，请检查用户余额</p>";
                            document.getElementById("bodys").innerHTML = content;
                        }
                    }
                });
            }
       }
   }
    $(".Payments").hide();
    function reduce(){
        $("#ids").val(1);
        $(".Payment1").hide();
        $(".Payments").show();
    }
    function Payments(){
        $("#ids").val(0);
        $(".Payment1").show();
        $(".Payments").hide();
    }
</script>